﻿<phone:PhoneApplicationPage
    x:Class="Fabrikam.Phone.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:conv="clr-namespace:Fabrikam.Phone.Converters"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    mc:Ignorable="d"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    toolkit:TiltEffect.IsTiltEnabled="True"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="False">


    <toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardIn"/>
            </toolkit:NavigationInTransition.Backward>
            <toolkit:NavigationInTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardIn"/>
            </toolkit:NavigationInTransition.Forward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Backward>
                <toolkit:TurnstileTransition Mode="BackwardOut"/>
            </toolkit:NavigationOutTransition.Backward>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:TurnstileTransition Mode="ForwardOut"/>
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>
    <phone:PhoneApplicationPage.Resources>
        <conv:BooleanToVisibilityConverter x:Key="VisibleIfTrue" Inverted="True" Not="False"    />
        <conv:BooleanToVisibilityConverter x:Key="VisibleIfNotTrue" Inverted="True" Not="True"    />
        <conv:StatusToBrushConverter x:Key="StatusToBrushConverter" />
    </phone:PhoneApplicationPage.Resources>

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar  >
            <shell:ApplicationBarIconButton IconUri="/Icons/add.png" IsEnabled="True" Text="Add" Click="ApplicationBarAddClicked"  />
            <shell:ApplicationBarIconButton IconUri="/Icons/sync.png" IsEnabled="True" Text="Sync" Click="ApplicationBarSyncClicked" />
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

    <!--Data context is set to sample data above and LayoutRoot contains the root grid where all other page content is placed-->
    <Grid x:Name="LayoutRoot">
        <Grid.Background>
            <ImageBrush ImageSource="Assets/Background.png"></ImageBrush>
        </Grid.Background>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>



        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="FABRIKAM FIBER" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock Text="Interventions" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel contains LongListSelector and LongListSelector ItemTemplate. Place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <phone:LongListSelector x:Name="MainLongListSelector" Margin="0,0,-12,0" 
                                    ItemsSource="{Binding ServiceTickets}" SelectionChanged="MainLongListSelector_SelectionChanged">
                <phone:LongListSelector.ItemTemplate>
                    <DataTemplate>
                        <Grid Margin="0,0,0,17">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <StackPanel Orientation="Vertical">

                                <TextBlock Text="{Binding CustomerFullName}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
                                <TextBlock Text="{Binding CustomerAddress}" TextWrapping="Wrap" Margin="12,-6,12,0" Style="{StaticResource PhoneTextSubtleStyle}"/>
                            </StackPanel>
                            <Rectangle  Margin="0,0,12,0"  HorizontalAlignment="Right" Grid.Column="1" Fill="{Binding StatusValue, Converter={StaticResource StatusToBrushConverter}}" Width="43" Height="43"/>
                        </Grid>
                    </DataTemplate>
                </phone:LongListSelector.ItemTemplate>
            </phone:LongListSelector>
        </Grid>

        <Grid RowSpan="2"   Visibility="{Binding IsLoading, Converter={StaticResource VisibleIfTrue}}" Name="WaitingGrid">
            <Rectangle Fill="Black" Opacity="0.6"></Rectangle>
            <Border HorizontalAlignment="Stretch" 
                    Background="Black"
                    Height="80" 
                    BorderBrush="White" BorderThickness="2"
                    Margin="50,0,50,0" VerticalAlignment="Center" >
                <Grid >
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <TextBlock Text="Sync in progress ..." HorizontalAlignment="Center"
                               Foreground="White" Style="{StaticResource PhoneTextAccentStyle}"></TextBlock>
                    <ProgressBar IsIndeterminate="True" Foreground="White" Grid.Row="1" />

                </Grid>
            </Border>
        </Grid>
    </Grid>

</phone:PhoneApplicationPage>